package com.example.myvideoplayer.Utils;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.myvideoplayer.Bean.Video;
import com.example.myvideoplayer.R;

import java.util.ArrayList;

public class VideoShowAdapter extends BaseAdapter {
    private ArrayList<Video> mData;
    private Context mContext;

    public VideoShowAdapter(ArrayList<Video> mData, Context mContext) {
        this.mData = mData;
        this.mContext = mContext;
    }

    @Override
    public int getCount() {
        return mData.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Log.i("adapter_getview", "getView: ");
        MyVideoAdapter.ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.video_show, parent, false);
            holder = new MyVideoAdapter.ViewHolder();
            holder.tv_video_title = convertView.findViewById(R.id.tv_video_name);
            holder.tv_video_duration = convertView.findViewById(R.id.tv_video_time);
            holder.iv_video_icon = convertView.findViewById(R.id.iv_video_cover);
            convertView.setTag(holder);
        } else {
            holder = (MyVideoAdapter.ViewHolder) convertView.getTag();
        }
        holder.tv_video_title.setText(mData.get(position).getName());
        holder.tv_video_duration.setText(Untils.formatTime(mData.get(position).getDuration()));
        holder.iv_video_icon.setImageBitmap(mData.get(position).getCover());
        return convertView;
    }

    static class ViewHolder {
        TextView tv_video_title;
        TextView tv_video_duration;
        ImageView iv_video_icon;
    }
}
